/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmSueldos.java
 *
 * Created on 10-oct-2011, 9:32:54
 */
package apiformularios.form;

import api.dom.Empleado;
import api.dom.Sueldo;
import api.dom.Utilitaria;
import api.gest.GestCamiones;
import api.gest.GestSueldo;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Luis
 */
public class FrmSueldos extends javax.swing.JInternalFrame {

    /** Creates new form FrmSueldos */
    public FrmSueldos() {
        initComponents();
        ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
        Utilitaria.listarEmpleadosCombo((DefaultComboBoxModel) this.cboxemp.getModel());
        this.txtnum.setText(String.valueOf(GestSueldo.getInstance().devolverUltimoNum()));
        Utilitaria.listarSueldos((DefaultTableModel) this.jTable2.getModel());
        Date hoy = new Date();
        dtpPago.setDate(hoy);

        this.btnModificar.setEnabled(false);
        this.btnEliminar.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtCorrespondiente = new javax.swing.JTextField();
        txtKm = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtPrecioKm = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtnum = new javax.swing.JTextField();
        txtKmPrecioRetorno = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtSueldo = new javax.swing.JTextField();
        txtFacturado = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnBuscar = new javax.swing.JButton();
        txtNombre1 = new javax.swing.JTextField();
        btnModificar = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        cboxemp = new javax.swing.JComboBox();
        txtKmRetorno = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        dtpPago = new com.toedter.calendar.JDateChooser();
        jLabel13 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        fechahasta = new com.toedter.calendar.JDateChooser();
        fechadesde = new com.toedter.calendar.JDateChooser();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Desde Fecha: ");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 80, -1, -1));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Hasta Fecha: ");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 110, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Correspondiente a:");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 140, -1, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Empleado :");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 170, 80, -1));
        getContentPane().add(txtCorrespondiente, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 140, 160, 20));

        txtKm.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKmKeyTyped(evt);
            }
        });
        getContentPane().add(txtKm, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 110, 120, 20));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Precio Km");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, 70, -1));

        txtPrecioKm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPrecioKmActionPerformed(evt);
            }
        });
        txtPrecioKm.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtPrecioKmKeyTyped(evt);
            }
        });
        getContentPane().add(txtPrecioKm, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 140, 120, -1));

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setText("Km retorno");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 80, -1));

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Precio km retorno");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, -1, -1));

        txtnum.setEditable(false);
        getContentPane().add(txtnum, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 80, 120, -1));

        txtKmPrecioRetorno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKmPrecioRetornoKeyTyped(evt);
            }
        });
        getContentPane().add(txtKmPrecioRetorno, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 200, 120, -1));

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setText("Sueldo");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 230, -1, -1));

        txtSueldo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSueldoKeyTyped(evt);
            }
        });
        getContentPane().add(txtSueldo, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 230, 160, -1));

        txtFacturado.setEnabled(false);
        getContentPane().add(txtFacturado, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 200, 160, -1));

        jTable2.setAutoCreateRowSorter(true);
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nro", "Empleado", "Fecha de Pago", "Facturado", "Sueldo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 259, 630, 250));

        jPanel1.setBackground(new java.awt.Color(153, 180, 209));
        jPanel1.setPreferredSize(new java.awt.Dimension(580, 71));

        jLabel12.setBackground(new java.awt.Color(51, 255, 51));
        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 48));
        jLabel12.setText("Sueldos");
        jLabel12.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap(476, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 650, 70));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Numero :");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
        jPanel2.add(btnBuscar, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 0, 90, 40));

        txtNombre1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNombre1KeyReleased(evt);
            }
        });
        jPanel2.add(txtNombre1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 150, -1));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 520, -1, 40));

        btnModificar.setText("Modifcar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        getContentPane().add(btnModificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 520, 80, 40));

        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAgregar, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 520, 80, 40));

        btnEliminar.setText("Eliminar");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        getContentPane().add(btnEliminar, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 520, 80, 40));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Km");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, -1, -1));

        getContentPane().add(cboxemp, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 170, 160, -1));

        txtKmRetorno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKmRetornoKeyTyped(evt);
            }
        });
        getContentPane().add(txtKmRetorno, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 170, 120, -1));

        jButton1.setText("Calcular Facturado en $");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 200, 150, -1));
        getContentPane().add(dtpPago, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 230, 120, -1));

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel13.setText("Fecha de pago");
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, -1, -1));

        jButton2.setText("...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 80, 30, -1));
        getContentPane().add(fechahasta, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 110, 170, -1));
        getContentPane().add(fechadesde, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 80, 170, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        Date date = new Date();
        date = (fechadesde.getDate());
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String fInicio = dateFormat.format(date);
        Date date1 = new Date();
        date = (dtpPago.getDate());
        DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");
        String fPago = dateFormat.format(date);
        Date date2 = new Date();
        date = (fechahasta.getDate());
        DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
        String fFin = dateFormat.format(date);

        Empleado objEmp = (Empleado) cboxemp.getSelectedItem();
        Sueldo objs = new Sueldo(Integer.parseInt(txtnum.getText()), fPago, fInicio, fFin, txtCorrespondiente.getText(), Integer.parseInt(txtKm.getText()),
                Double.parseDouble(txtPrecioKm.getText()), Integer.parseInt(txtKmRetorno.getText()), Double.parseDouble(txtKmPrecioRetorno.getText()),
                Integer.parseInt(txtSueldo.getText()), Double.parseDouble(txtFacturado.getText()), objEmp);

        String o = (String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 0)));

        int i = Integer.parseInt(o);
        GestSueldo.getInstance().modificarSueldo(objs);
        this.txtnum.setText(String.valueOf(GestSueldo.getInstance().devolverUltimoNum()));
        this.txtCorrespondiente.setText("");
        this.txtFacturado.setText("");
        this.txtKm.setText("");
        this.txtKmPrecioRetorno.setText("");
        this.txtKmRetorno.setText("");
        this.txtSueldo.setText("");
        this.btnAgregar.setEnabled(true);
        this.btnModificar.setEnabled(false);

        this.txtPrecioKm.setText("");
        Utilitaria.limpiarJtables((DefaultTableModel) jTable2.getModel());
        Utilitaria.listarSueldos((DefaultTableModel) jTable2.getModel());
    }
        // TODO add your handling code here:}//GEN-LAST:event_btnModificarActionPerformed

        private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        try {
            Date date = new Date();
            date = (fechadesde.getDate());
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            String fInicio = dateFormat.format(date);
            Date date1 = new Date();
            date = (dtpPago.getDate());
            DateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");
            String fPago = dateFormat.format(date);
            Date date2 = new Date();
            date = (fechahasta.getDate());
            DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
            String fFin = dateFormat.format(date);
            Empleado objEmp = (Empleado) cboxemp.getSelectedItem();
            Sueldo objS = new Sueldo(Integer.parseInt(txtnum.getText()), fPago, fInicio, fFin, txtCorrespondiente.getText(), Integer.parseInt(txtKm.getText()),
                    Double.parseDouble(txtPrecioKm.getText()), Integer.parseInt(txtKmRetorno.getText()), Double.parseDouble(txtKmPrecioRetorno.getText()),
                    Integer.parseInt(txtSueldo.getText()), Double.parseDouble(txtFacturado.getText()), objEmp);
            GestSueldo.getInstance().altaSueldo(objS);
            this.txtnum.setText(String.valueOf(GestSueldo.getInstance().devolverUltimoNum()));
            Utilitaria.limpiarJtables((DefaultTableModel) this.jTable2.getModel());
            Utilitaria.listarSueldos((DefaultTableModel) this.jTable2.getModel());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Falto ingresar algun dato obligatorio");

        }
    }
// TODO add your handling code here:         String fecha = Utilitaria.convertirDateString(this.jDateChooser1.getDate());         Camion objCamion = (Camion) this.cCamiones.getSelectedItem();         Gasto objGasto = new Gasto(Integer.parseInt(this.txtNumero.getText()), fecha, this.txtViatico.getText(), Double.parseDouble(this.txtGasoil.getText()), Double.parseDouble(this.txtLubricante.getText()), Double.parseDouble(this.txtCubierta.getText()), Double.parseDouble(this.txtTaller.getText()), Double.parseDouble(this.txtVarios.getText()), Double.parseDouble(this.txtSueldo.getText()), Double.parseDouble(this.txtAmortiz.getText()), Double.parseDouble(this.txtSeguro.getText()), objCamion);         GestGastos.getInstance().altaGasto(objGasto);     }//GEN-LAST:event_btnAgregarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try {
            String fechaini = Utilitaria.convertirDateString(fechadesde.getDate());
            Date fechafin = fechahasta.getDate();
            Date f = Utilitaria.convertirStringDate(fechaini);
            String x = String.valueOf(Utilitaria.calcularFacturado(f, fechafin, (Empleado) cboxemp.getSelectedItem()));
            txtFacturado.setText(x);
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(rootPane, "Seleccione las fechas entre las cuales se calculara");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtKmKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKmKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != evt.VK_BACK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtKmKeyTyped

    private void txtPrecioKmKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioKmKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != evt.VK_BACK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtPrecioKmKeyTyped

    private void txtKmRetornoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKmRetornoKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != evt.VK_BACK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtKmRetornoKeyTyped

    private void txtKmPrecioRetornoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKmPrecioRetornoKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != evt.VK_BACK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtKmPrecioRetornoKeyTyped

    private void txtSueldoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSueldoKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        if (((caracter < '0')
                || (caracter > '9'))
                && (caracter != evt.VK_BACK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtSueldoKeyTyped

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        try {
            if (jTable2.getSelectedRow() < 0) {
                JOptionPane.showMessageDialog(null, "SELECCIONE UN PAGO", "Fatal Error", JOptionPane.ERROR_MESSAGE);
            } else {
                String x = (String.valueOf(this.jTable2.getValueAt(jTable2.getSelectedRow(), 0)));
                GestSueldo.getInstance().bajaSueldo(x);
                Utilitaria.limpiarJtables((DefaultTableModel) this.jTable2.getModel());
                Utilitaria.listarSueldos((DefaultTableModel) jTable2.getModel());
                this.txtnum.setText(String.valueOf(GestSueldo.getInstance().devolverUltimoNum()));
                this.btnEliminar.setEnabled(false);
                this.txtCorrespondiente.setText("");
                this.txtFacturado.setText("");
                this.txtKm.setText("");
                this.txtKmPrecioRetorno.setText("");
                this.txtKmRetorno.setText("");
                this.txtSueldo.setText("");
                this.btnAgregar.setEnabled(true);
                this.btnModificar.setEnabled(false);

            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "ERROR AL ELIMINAR PAGO", "Fatal Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void txtPrecioKmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPrecioKmActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPrecioKmActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.txtnum.setText(String.valueOf(GestSueldo.getInstance().devolverUltimoNum()));
        this.txtCorrespondiente.setText("");
        this.txtFacturado.setText("");
        this.txtKm.setText("");
        this.txtKmPrecioRetorno.setText("");
        this.txtKmRetorno.setText("");
        this.txtSueldo.setText("");
        this.btnAgregar.setEnabled(true);
        this.btnModificar.setEnabled(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
        // TODO add your handling code here:
        String o = (String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 0)));
        int i = Integer.parseInt(o);
        Sueldo objSueldo = GestSueldo.getInstance().devolverSueldoNum(i);
        this.btnEliminar.setEnabled(true);
        this.txtCorrespondiente.setText(objSueldo.getCorrespondienteA());
        this.txtFacturado.setText(String.valueOf(objSueldo.getFacturado()));
        this.txtKm.setText(String.valueOf(objSueldo.getKm()));
        this.txtPrecioKm.setText(String.valueOf(objSueldo.getPrecioKm()));
        this.txtKmPrecioRetorno.setText(String.valueOf(objSueldo.getPrecioKmRetorno()));
        this.txtKmRetorno.setText(String.valueOf(objSueldo.getKmRetorno()));
        this.txtSueldo.setText(String.valueOf(objSueldo.getSueldo()));
        this.txtnum.setText(o);

        this.btnModificar.setEnabled(true);
        this.btnAgregar.setEnabled(false);
    }//GEN-LAST:event_jTable2MouseClicked

    private void txtNombre1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombre1KeyReleased
        // TODO add your handling code here:
        try {
            if ("".equals(txtNombre1.getText())) {
                JOptionPane.showMessageDialog(rootPane, "Ingrese numero de sueldo a buscar");
            } else {
                DefaultTableModel modelo32 = (DefaultTableModel) jTable2.getModel();
                modelo32.setRowCount(0);
                Sueldo objS = GestSueldo.getInstance().devolverSueldoNum(Integer.parseInt(txtNombre1.getText()));
                Object[] objSA = {objS.getSueldoNumero(), objS.getObjE().getpNombre(), objS.getFechaPago(), objS.getFacturado(), objS.getSueldo()};
                modelo32.addRow(objSA);
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(null, "No exsiste ese sueldo");
            txtNombre1.setText("");
            this.jTable2.setModel(Utilitaria.listarSueldos((DefaultTableModel) jTable2.getModel()));
        }
    }//GEN-LAST:event_txtNombre1KeyReleased
    /**/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificar;
    private javax.swing.JComboBox cboxemp;
    private com.toedter.calendar.JDateChooser dtpPago;
    private com.toedter.calendar.JDateChooser fechadesde;
    private com.toedter.calendar.JDateChooser fechahasta;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField txtCorrespondiente;
    private javax.swing.JTextField txtFacturado;
    private javax.swing.JTextField txtKm;
    private javax.swing.JTextField txtKmPrecioRetorno;
    private javax.swing.JTextField txtKmRetorno;
    private javax.swing.JTextField txtNombre1;
    private javax.swing.JTextField txtPrecioKm;
    private javax.swing.JTextField txtSueldo;
    private javax.swing.JTextField txtnum;
    // End of variables declaration//GEN-END:variables
}
